package com.haoan.index.service.impl;


import java.util.List;
import javax.annotation.Resource;

import com.haoan.index.mapper.IntroduceMapper;
import com.haoan.index.service.IntroduceService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.haoan.index.common.enums.ValiFlag;

import com.haoan.index.mapper.PersonnelMapper;
import com.haoan.index.domain.Personnel;
import com.haoan.index.service.PersonnelService;

/**
 * 企业人员Service业务层处理
 *
 * @author autoGen
 * @date 2025-01-03
 */
@Service
public class PersonnelServiceImpl extends ServiceImpl<PersonnelMapper,Personnel> implements PersonnelService
{
    @Resource
    private IntroduceMapper introduceMapper;
    /**
     * 查询企业人员
     *
     * @param id 企业人员主键
     * @return 企业人员
     */
    @Override
    public Personnel selectPersonnelById(Long id)
    {
        return baseMapper.selectById(id);
    }

    /**
     * 查询企业人员列表
     *
     * @param personnel 企业人员
     * @return 企业人员
     */
    @Override
    public List<Personnel> selectPersonnelList(Personnel personnel)
    {
        LambdaQueryWrapper<Personnel> queryWrapper = new LambdaQueryWrapper<>();
        //todo 添加查询条件
        queryWrapper.eq(personnel.getId() != null, Personnel::getId, personnel.getId());
        queryWrapper.eq(personnel.getIntroduceId() != null, Personnel::getIntroduceId, personnel.getIntroduceId());
        queryWrapper.eq(personnel.getName() != null, Personnel::getName, personnel.getName());
        queryWrapper.eq(personnel.getPosts() != null, Personnel::getPosts, personnel.getPosts());
        queryWrapper.eq(personnel.getPhoto() != null, Personnel::getPhoto, personnel.getPhoto());
        queryWrapper.eq(personnel.getBrief() != null, Personnel::getBrief, personnel.getBrief());
        queryWrapper.eq(personnel.getStatus() != null, Personnel::getStatus, personnel.getStatus());
        queryWrapper.eq(personnel.getCreateTime() != null, Personnel::getCreateTime, personnel.getCreateTime());
        queryWrapper.eq(personnel.getCreateBy() != null, Personnel::getCreateBy, personnel.getCreateBy());
        queryWrapper.eq(personnel.getUpdateTime() != null, Personnel::getUpdateTime, personnel.getUpdateTime());
        queryWrapper.eq(personnel.getUpdateBy() != null, Personnel::getUpdateBy, personnel.getUpdateBy());
        queryWrapper.eq(Personnel::getValiFlag,ValiFlag.VALID );
        List<Personnel> list = baseMapper.selectList(queryWrapper);
        return list;
    }

    /**
     * 新增企业人员
     *
     * @param personnel 企业人员
     * @return 结果
     */
    @Transactional
    @Override
    public int insertPersonnel(Personnel personnel)
    {
        return baseMapper.insert(personnel);
    }

    /**
     * 修改企业人员
     *
     * @param personnel 企业人员
     * @return 结果
     */
    @Transactional
    @Override
    public int updatePersonnel(Personnel personnel)
    {
        return baseMapper.updateById(personnel);
    }

    /**
     * 批量删除企业人员
     *
     * @param ids 需要删除的企业人员主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deletePersonnelByIds(Long [] ids)
    {
        Personnel personnel = new Personnel();
        personnel.setValiFlag(ValiFlag.INVALID);
        LambdaQueryWrapper<Personnel> updQw = new LambdaQueryWrapper<>();
        updQw.in(Personnel::getId, ids);
        return baseMapper.update(personnel, updQw);
    }

    /**
     * 删除企业人员信息
     *
     * @param id 企业人员主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteById(Long id)
    {
        Personnel personnel = getById(id);
        personnel.setValiFlag(ValiFlag.INVALID);
        return baseMapper.updateById(personnel);
    }
}
